package com.candy.service.impl;

import com.candy.bean.UserInfo;
import com.candy.dao.UserInfoMapper;
import com.candy.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserInfoServiceImpl implements IUserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public List<UserInfo> getUserInfoes(UserInfo userInfo) {

        return userInfoMapper.getUserInfoes(userInfo);
    }


    @Override
    public boolean addOrUpdateUserInfo(UserInfo userInfo) {
//        判断参数中是否传递id属性值，
        int num=0;
//        若传进来id值不为空，则执行修改（更新）方法
        if(userInfo.getId()!=null){
            num=userInfoMapper.updateByPrimaryKeySelective(userInfo);
        }else{
            //        若传递进来的id值为空，则执行新增操作
            num= userInfoMapper.insertSelective(userInfo);
        }
        if (num>0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public boolean deleteUserInfoByID(Integer id) {

        UserInfo userInfo=new UserInfo();
        userInfo.setId(id);
        userInfo.setIsdelete(1);
        int num=userInfoMapper.updateByPrimaryKeySelective(userInfo);
        if (num>0){
            return true;
        }else {
            return false;
        }


    }
}
